<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {

	private $Verify = '';
	public function _initialize(){
		if($this->Verify == ''){
	    	$config =    array(
	    	    'fontSize'    =>    35,    // 验证码字体大小
	    	    'length'      =>    2,     // 验证码位数    
	    	    'useNoise'    =>    false, // 关闭验证码杂点
	    	);
			$this->Verify = new \Think\Verify($config);
		}
	}
    public function code(){
		$this->Verify->entry();
    }


    public function login(){
    	if(session('UserInfo')){
    		header('location:'.U('Index/index'));
    	}
    	$this->display();
    }


    public function login_c(){
    	$name = I('post.name');
    	$pwd = I('post.pwd');
    	$code = I('post.code');
    	if(!$name || !$pwd || !$code){
    		exit('e1');	//信息不得为空
    	}
		if(!$this->Verify->check($code)){
			exit('e2');	//验证码不正确
		}
		$m = M('Admins');
		$res = $m->where(array('name'=>$name))->find();
		if($res['pwd'] == md5($pwd)){
			session('UserInfo',$res);
			exit('ok');
		}else{
			exit('e3');	//用户名或密码错误
		}
   
    }


    public function exits(){
    	session('UserInfo',null);
    	echo 'exit';
    }



}
